<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head th:include="common/header"></head>
<body>
	<div class="layui-fluid">

		<!-- 导航菜单 -->
		<div th:replace="common/system/system_fragment :: system_menu('支付宝生活号')"></div>

		<!-- 当前位置 -->
		<div
			th:replace="common/system/system_fragment :: system_location('支付宝生活号', '消息管理')"></div>

		<div class="layui-row yy-margin-top-10">
			<!-- 查询 -->
			<div class="layui-collapse" lay-accordion="lay-accordion">
				<div class="layui-colla-item">
					<h2 class="layui-colla-title">查询</h2>
					<div class="layui-colla-content layui-show">
						<div class="layui-form layui-form-pane">
						
							<div class="layui-form-item">
								<label class="layui-form-label layui-bg-orange">文本内容</label>
								<div class="layui-input-block">
									<input type="text" name="content" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label layui-bg-orange">图文标题</label>
								<div class="layui-input-block">
									<input type="text" name="title" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label layui-bg-orange">消息类型</label>
									<div class="layui-input-block">
										<input type="radio" name="type" title="文本" value="1" /> 
										<input type="radio" name="type" title="图文" value="2" />
									</div>
								</div>
							
								<div class="layui-inline">
									<div class="layui-input-block">
										<button class="layui-btn yy-float-right" onclick="queryMethod();">查询</button>
									</div>
								</div>
							</div>
							
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="layui-row">
			<a class="layui-btn yy-margin-top-10" href="javascript:show();"
				th:each="str,iterStat:${USER_PERMISSION_KEY}"
				th:if="${str eq 'message:show'}"> <i class="layui-icon">&#xe65d;</i>
				查看
			</a> 
			<a class="layui-btn yy-margin-top-10"
				th:href="@{'/message/messageform/-1'}"
				th:each="str,iterStat:${USER_PERMISSION_KEY}"
				th:if="${str eq 'message:add'}"> <i class="layui-icon">&#xe654;</i>
				添加
			</a> 
			<a class="layui-btn yy-margin-top-10"
				th:each="str,iterStat:${USER_PERMISSION_KEY}"
				th:if="${str eq 'message:update'}" onclick="edit();"> <i
				class="layui-icon">&#xe642;</i> 编辑
			</a> 
			<a class="layui-btn layui-btn-danger yy-margin-top-10"
				th:each="str,iterStat:${USER_PERMISSION_KEY}"
				th:if="${str eq 'message:delete'}" onclick="del();"> <i
				class="layui-icon">&#xe640;</i> 删除
			</a>

			<!-- 表格 -->
			<table id="messageTable" class="yy-margin-top-10"></table>
		</div>

	</div>

	<!-- 引入js -->
	<div th:replace="common/script"></div>

	<script th:inline="none">
	/*<![CDATA[*/
	
	var tableObj;
	var table;
	
	//查询
	var queryMethod = function(){
		
		var content = $("input[name=content]").val();
		var title = $("input[name=title]").val();
		var type = $("input[name=type]:checked").val();
		
		tableObj.reload({
			where:{
				content:content,
				title:title,
				type:type
			}
		});
	};
		
	;!function(){
		
		table = layui.table;
		
		tableObj = table.render({
			elem:"#messageTable",
			id:"messageTable",
			loading:true,
			url:"/message/messageTable",
			skin:"line",
			even:true,
			cols:[[
				{field:"id", title:"id", width:0, fixed:'left', checkbox:true},
				{field:"type", title:"消息类型", width:100, fixed:true, templet:'#typeTemp'},
				{field:"content", title:"文本内容", width:400},
				{field:"title", title:"图文标题", width:400},
				{field:"createDate", title:"创建日期", width:120, sort:true},
				{field:"updateDate", title:"更新日期", width:120, sort:true}
			]],
			page:true,
			height:'full',//自适应高度，数据多高表格多高
			limits:[10,30,50,100],
			limit:10,
			size:'lg'
		});
		
	}();
	
	//查看
	function show(id){
		var checkStatus = table.checkStatus('messageTable');
		if(checkStatus.data.length <= 0 || checkStatus.data.length > 1){
			$.prompt.alert("请选择并且只能选择一条数据!");
			return;
		}
		$.logs.info(checkStatus);
		var id = checkStatus.data[0].id;
		var href="/message/show/"+id;
		$.logs.info(href);
		window.location.href=href;
	}
	
	//编辑
	function edit(){
		var checkStatus = table.checkStatus('messageTable');
		if(checkStatus.data.length <= 0 || checkStatus.data.length > 1){
			$.prompt.alert("请选择并且只能选择一条数据!");
			return;
		}
		var id = checkStatus.data[0].id;
		var href="/message/messageform/"+id;
		$.logs.info(href);
		window.location.href=href;
	}
	
	//删除
	function del(){
		var checkStatus = table.checkStatus('messageTable');
		if(checkStatus.data.length <= 0 || checkStatus.data.length > 1){
			$.prompt.alert("请选择并且只能选择一条数据!");
			return;
		}
		var id = checkStatus.data[0].id;
		$.prompt.delPromptBox("确定要删除吗？", "/message/delmessage/"+id, tableObj);
	}
	/*]]>*/
	</script>

	<script type="text/html" id="typeTemp">
	{{#  if(d.type == 1){ }}
		<span class="yy-text-color-red">文本消息</span>
	{{#  } else if(d.type == 2) { }}
		<span class="yy-text-color-blue">图文消息</span>
	{{#  } }}
	</script>

</body>

</html>